import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/bean/girl_data.dart';
import 'package:flutter_app/compents/contrants_info.dart';
import 'package:get/get.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

///多图查看
class PhotoViewMultiple extends StatefulWidget {

  // List<Girl> images = [];
  // int index = 0;
  // String heroTag;
  // PageController controller;
  //
  //
  // PhotoViewMultiple(
  //     {Key key,
  //     @required this.images,
  //     this.index,
  //     this.controller,
  //     this.heroTag})
  //     : super(key: key) {
  //   controller = PageController(initialPage: index);
  // }

  @override
  _PhotoViewMultiple createState() => _PhotoViewMultiple();
}

class _PhotoViewMultiple extends State<PhotoViewMultiple> {
  int currentIndex = 0;
  List<Girl> images = [];
  int index = 0;
  String heroTag;
  PageController controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // currentIndex = widget.index;
    images = Get.arguments[ConstantInfo.PHOTO_VIEW_LIST];
    index = Get.arguments[ConstantInfo.PHOTO_VIEW_INDEX];
    heroTag = Get.arguments[ConstantInfo.PHOTO_VIEW_TAG];
    currentIndex = index;
    controller = PageController(initialPage: index);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
            top: 0,
            left: 0,
            bottom: 0,
            right: 0,
            child: Container(
                child: PhotoViewGallery.builder(
                  scrollPhysics: const BouncingScrollPhysics(),
                  builder: (BuildContext context, int index) {
                    return PhotoViewGalleryPageOptions(
                      imageProvider: NetworkImage(images[index].imageUrl),
                      heroAttributes: heroTag.isNotEmpty
                          ? PhotoViewHeroAttributes(tag: heroTag)
                          : null,
                    );
                  },
                  itemCount: images.length,
                  backgroundDecoration: null,
                  pageController: controller,
                  enableRotation: true,
                  onPageChanged: (index) {
                    setState(() {
                      currentIndex = index;
                    });
                  },
                )),
          ),
          Positioned(
            top: MediaQuery.of(context).padding.top + 15,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${currentIndex + 1}/${images.length}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top,
            child: IconButton(
              icon: Icon(
                Icons.close,
                size: 30,
                color: Colors.white,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
        ],
      ),
    );
  }
}
